#!/usr/bin/perl -w
####################################################
# Copyright (c) 2002-2007 BioWare Corp.
# http://www.bigdaddymonitor.org
#
# This file is part of the BigDaddy Monitoring
# program. It is free software distributed under
# the terms of the BSD License. It is ditributed
# in the hopes that it will be useful, but
# WITHOUT ANY WARRANTY; without event the implied
# warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
#
# The BSD License is available from:
# http://www.opensource.org/licenses/bsd-license.php
####################################################
#=============================================================================#
#BigDaddy Module: Windows SNMP CPU Checker
#Author: Craig Miller
#Date: 19.10.2006
#=============================================================================#

=intro

=cut

use strict;
use POSIX qw(ceil);

my ($sServer) = @ARGV;
my @aResults=`snmpwalk -c public -v 1 $sServer HOST-RESOURCES-MIB::hrProcessorLoad`;
my $nCPUCount=scalar @aResults;
my $nCPULoad;

foreach my $sLine (@aResults)
{
    if ($sLine =~ m/hrProcessorLoad.([0-9]+) = INTEGER: ([0-9]+)/i)
    {
        $nCPULoad+=$2;
    }
}

$nCPULoad=ceil($nCPULoad/$nCPUCount);

print $nCPULoad;   

